package mao.leetcode.others.leetcode114;

public class Solution {

    //参考莫里斯遍历。
    public void flatten(TreeNode root) {
        TreeNode find = null;
        TreeNode temp;
        while (root != null) {
            if (root.left != null) {
                temp = root.right;
                root.right = root.left;
                root.left = null;
                find = root.right;
                while (find.right != null) find = find.right;
                find.right = temp;
            }
            root=root.right;
        }
    }
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }
}
